package com.wondersgroup.fjzlpt.tbxt.controller.rest.wsj;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.tbxt.beans.req.wsjYb.QueryOneReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.req.wsjYb.SaveReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.BaseRespBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.wsjYb.QueryOneRespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.wondersgroup.fjzlpt.tbxt.service.inter.wsj.WsjYbService;

/**
 * 卫生局月报
 */
@RestController
@RequestMapping("wsjyb")
@Api(value = "卫生局月报标准接口", tags = "WsjYbRestController", description = "卫生局月报API")
public class WsjYbRestController {

    @Autowired
    private WsjYbService wsjYbService;

    /**
     * 保存：卫生局-综合信息月报
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "保存", notes = "保存卫生局月报", response = BaseRespBean.class)
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public JSONObject save(HttpServletRequest request, SaveReqBean saveReqBean) {
        Map map = RequestUtils.GetParameterMap(request);
        map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
        map.put("JGMC", (String) QuickPrincipalUtils.getUserinfoByKey(request, "YLJGMC"));
        map.put("JGLB", QuickPrincipalUtils.getJglbdm(request));
        map.put("XZQH", QuickPrincipalUtils.getXzqhdm(request));
        return wsjYbService.save(map);
    }

    /**
     * 根据机构id和填报时间，查询某机构填报记录
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询卫生局月报",response = QueryOneRespBean.class)
    @RequestMapping(value = "queryOne", method = RequestMethod.POST)
    public JSONObject queryOne(HttpServletRequest request, QueryOneReqBean queryOneReqBean) {
        Map<String, String> map = RequestUtils.GetParameterMap(request);
        if (StringUtils.isEmpty(map.get("YLJGID"))) {
            map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
            map.put("JGMC", (String) QuickPrincipalUtils.getUserinfoByKey(request, "YLJGMC"));
        }
        return wsjYbService.queryOne(map);
    }
}
